// pages/Register/index.js
Page({


  data: {},
  sex: null,
  file: null,
  formSubmit: function (e) {
    if (this.sex === null) {

      wx.showToast({
        title: '请选择您的性别',
        icon: "error",
      });
      return;
    }
    if (this.file === null) {
      wx.showToast({
        title: '请上传您的头像',
        icon: "error",
      });
      return;
    }
    if (e.detail.value.u_email === "") {
      wx.showToast({
        title: '请输入您的邮箱',
        icon: "error",
      });
      return;
    }
    if (e.detail.value.u_name === "") {
      wx.showToast({
        title: '请输入您的昵称',
        icon: "error",
      });
      return;
    }
    if (e.detail.value.u_password === "") {
      wx.showToast({
        title: '请输入您的密码',
        icon: "error",
      });
      return;
    }
    if (e.detail.value.u_telphone === "") {
      wx.showToast({
        title: '请输入您的电话',
        icon: "error",
      });
      return;
    }
    wx.uploadFile({
      url: 'http://460d80b632.zicp.vip/WeChat/register.php',
      filePath: this.file,
      name: 'file',
      formData: {
        'u_email': e.detail.value.u_email,
        'u_name': e.detail.value.u_name,
        'u_password': e.detail.value.u_password,
        'u_telphone': e.detail.value.u_telphone,
        'u_sex': this.sex,
      },
      success: (res) => {

        let jsonObj = JSON.parse(res.data);

        if (!jsonObj.success) {
          wx.showToast({
            title: jsonObj.msg,
            icon: "error",
          });
          return;
        }
        wx.setStorage({
          key: "user",
          data: jsonObj[0]
        });
        wx.setStorage({
          key: "property",
          data: jsonObj[1]
        });
        wx.reLaunch({
          url: '/pages/User/index',
        });
      }
    })
  },
  image_upload: function (params) {
    // var sex = this.sex;

    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: res => {
        this.file = res.tempFilePaths[0];
      }
    })
  },

  onLoad: function (options) {

  },
  radioSex: function (e) {
    this.sex = e.detail.value
  }
})